package com.lglbc;

import sun.misc.GC;

public class FinalizeEscapeGC {
    public static FinalizeEscapeGC GC_OK = null;
    public void isAlive(){
        System.out.println("I`m alive");
    }

    @Override
    protected void finalize() throws Throwable {
        super.finalize();
        GC_OK = this;
    }

    public static void main(String[] args) throws InterruptedException {
        GC_OK = new FinalizeEscapeGC();
        GC_OK = null;
        System.gc();
        Thread.sleep(5000);
        if (GC_OK!=null){
            GC_OK.isAlive();
        }else{
            System.out.println("i`m dead");
        }
        GC_OK = null;
        System.gc();
        Thread.sleep(5000);
        if (GC_OK!=null){
            GC_OK.isAlive();
        }else{
            System.out.println("i`m dead");
        }
    }
}
